Count Property (AddressEntries Collection)
The Count
property returns the number of AddressEntry
Syntax
objAddrEntriesColl.Count
Data Type
Long
Remarks
The Count
property is useful for determining whether an AddressEntries collection is
empty or not.
A large
collection cannot always maintain an accurate count of its members, and the Count
property cannot be used as the collection s size when it has a very large value
such as mapiMaxCount. Programmers needing to access individual objects
in a large collection are strongly advised to use the Visual Basic For Each
statement or the Get methods.
The
recommended procedures for traversing a large collection are, in decreasing
order of preference:
1. Global selection, such as the Visual Basic For
Each statement
2. The Get methods, particularly GetFirst and GetNext
3. An indexed loop, such as the Visual Basic For
... Next construction
If the
address book provider cannot supply the precise number of AddressEntry objects,
the OLE Messaging Library returns a very large number for the Count
property. On 32-bit platforms, this value is mapiMaxCount, which equals
2^31 - 1, or 2147483647. On other platforms, mapiMaxCount is not
defined, and the OLE Messaging Library returns -1. A program on such a
platform must be careful that -1 does not prematurely terminate any
iteration based on the Count property.
Programmers
using an indexed loop terminating on the Count property must also check
each returned object for a value of Nothing. The loop must proceed
forward from the beginning of the collection, and the index must have initial
and increment values of 1. Results are undefined for any other procedure.
The use of
the Item
Example
This code
fragment counts the AddressEntry objects in a user s personal address list
(PAL):
Dim i As Integer ' loop index / object counter
Dim myPAL as Object ' personal address list
' get AddressEntries collection of PAL AddressList
Set myPAL = MAPI.Session.AddressLists.Item( Personal
Address List )
' make sure returned collection object is valid
If myPAL Is Nothing Then
' MsgBox
"PAL object is invalid"
' Exit
End If
' see if PAL is empty
i = 0
If 0 = myPAL.Count Then
' MsgBox
"No items in PAL"
' Exit; i
= 0 is correct value
End If
' get exact count of AddressEntry members in PAL
For i = 1 To myPAL.Count Step 1
If
myPAL.Item(i) Is Nothing Then
i = i - 1
' rectify count
' Exit;
value of Nothing means end of collection
End If
Next i